<template>
  <div v-if="first[0]">
    <swiper class="swiper"
      :gigodata="{
        loop: true,
        autoplay: {
          delay: 2500,
          disableOnInteraction: false,
        }
      }"
    >
      <div class="swiper-slide" v-for="item in first[0].banners" :key="item.id">
        <img :src="item.bannerImgSrc">
      </div>
    </swiper>
    <div class="server margin">
      <img :src="first[1].bannerImgSrc" alt="">
    </div>
    <div class="margin furcate">
      <div v-for="item in first[2].banners" :key="item.id">
        <img :src="item.bannerImgSrc" alt="">
      </div>
    </div>
    <div class="margin">
      <img :src="first[3].bannerImgSrc" alt="">
    </div>
    <div class="margin">
      <img :src="first[4].bannerImgSrc" alt="">
    </div>
    <div class="margin">
      <img :src="first[5].bannerImgSrc" alt="">
    </div>
    <div class="margin special">
      <div v-for='item in first[6].banners' :key="item.id">
        <img :src="item.bannerImgSrc" alt="">
      </div>
      <div class="products">
        <div class="single-goods" v-for="item in first[6].products" :key="item.parentProductId" @click="handleDetail(item.productId,item)">
          <img :src="item.productImg" alt="">
          <span>{{ item.productTitle }}</span>
          <span>￥{{ item.sellPrice }}</span>
        </div>
      </div>
    </div>
    <div class="margin special">
      <div v-for='item in first[7].banners' :key="item.id">
        <img :src="item.bannerImgSrc" alt="">
      </div>
      <div class="products">
        <div class="single-goods" v-for="item in first[7].products" :key="item.parentProductId" @click="handleDetail(item.productId,item)">
          <img :src="item.productImg" alt="">
          <span>{{ item.productTitle }}</span>
          <span>￥{{ item.sellPrice }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import swiper from '@/components/Swiper'
export default {
  data () {
    return {
      first: []
    }
  },
  components: {
    swiper
  },
  mounted () {
    axios.get('/v2/page?pageId=1&tabId=1&currentPage=1&pageSize=8&_=1583387231365').then(res => {
      this.first = res.data.data.modules.map(item => item.moduleContent)
    })
  },
  methods: {
    handleDetail (goodsId, goods) {
      localStorage.setItem('goods', JSON.stringify(goods))
      this.$router.push(`/detail/${goodsId}`)
    }
  }
}
</script>

<style lang="scss" scoped>
img{
  width: 100%;
}
.swiper{
  height: 275px;
}
.furcate {
  box-sizing: border-box;
  background: white;
  padding: 30px 0px 15px;
  display: flex;
  justify-content: space-evenly;
  div{
    width: 29%;
  }
}
.special {
  padding: 30px 15px 10px;
  background: white;
  .products{
    display: flex;
    justify-content: space-between;
    .single-goods{
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 30%;
      font-size: 14px;
      span{
        width: 100%;
        overflow:hidden;
        white-space:nowrap;
        text-overflow:ellipsis;
        text-align: center;
      }
    }
  }
}
</style>
